﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TETRIS_v01.FieldObjects
{
    public class Stick : Shape
    
    //                [1]
    //  [1][■][3][4]  [■]
    //                [3]
    //                [4]

    {
        public Stick(ConsoleColor color)
        {            
            b1 = new Block(0, 0, color);
            b2 = new Block(1, 0, color);
            b3 = new Block(2, 0, color);
            b4 = new Block(3, 0, color);
            Position = Angle.Degree0;    
        }

        public override void Rotate(byte repeat)
        {
            for (int i = 0; i < repeat; i++)
            {
                switch (this.Position)
                {
                    case Angle.Degree0:
                    case Angle.Degree180:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 1,-1);
                            b3.ChangeCoordinates(-1, 1);
                            b4.ChangeCoordinates(-2, 2);
                        } break;
                    case Angle.Degree90:
                    case Angle.Degree270:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates(-1, 1);
                            b3.ChangeCoordinates( 1,-1);
                            b4.ChangeCoordinates( 2,-2);
                        } break;
                }
            }            
        }
     }

    public class Square : Shape

    //  [1][2]
    //  [4][3]

    {
        public Square(ConsoleColor color)
        {
            b1 = new Block(0, 0, color);
            b2 = new Block(1, 0, color);
            b3 = new Block(1, 1, color);
            b4 = new Block(0, 1, color);
        }
    }

    public class Shape_Z : Shape

    //  [1][2]         [4]
    //     [■][4]   [2][■]
    //              [1]

    {
        public Shape_Z(ConsoleColor color)
        {
            b1 = new Block(0, 0, color);
            b2 = new Block(1, 0, color);
            b3 = new Block(1, 1, color);
            b4 = new Block(2, 1, color);
        }
        public override void Rotate(byte repeat)
        {
            for (int i = 0; i < repeat; i++)
            {
                switch (this.Position)
                {
                    case Angle.Degree0:
                    case Angle.Degree180:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 0, 2);
                            b2.ChangeCoordinates(-1, 1);
                            b4.ChangeCoordinates(-1,-1);
                        } break;
                    case Angle.Degree90:
                    case Angle.Degree270:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates(0,-2);
                            b2.ChangeCoordinates(1,-1);
                            b4.ChangeCoordinates(1, 1);
                        } break;
                }
            }
        }
    }

    public class Shape_Z_reverse : Shape

    //     [3][4]   [4]
    //  [1][■]      [3][■]
    //                 [1]

    {
        public Shape_Z_reverse(ConsoleColor color)
        {
            b1 = new Block(0, 1, color);
            b2 = new Block(1, 1, color);
            b3 = new Block(1, 0, color);
            b4 = new Block(2, 0, color);
        }
        public override void Rotate(byte repeat)
        {
            for (int i = 0; i < repeat; i++)
            {
                switch (this.Position)
                {
                    case Angle.Degree0:
                    case Angle.Degree180:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 1, 1);
                            b3.ChangeCoordinates(-1, 1);
                            b4.ChangeCoordinates(-2, 0);
                        } break;
                    case Angle.Degree90:
                    case Angle.Degree270:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates(-1,-1);
                            b3.ChangeCoordinates( 1,-1);
                            b4.ChangeCoordinates( 2, 0);
                        } break;
                }
            }
        }
    }

    public class Shape_L : Shape

    //        [4]   [1]                [4][3]
    //  [1][■][3]   [■]     [3][■][1]     [■]
    //              [3][4]  [4]           [1]    

    {
        public Shape_L(ConsoleColor color)
        {
            b1 = new Block(0, 1, color);
            b2 = new Block(1, 1, color);
            b3 = new Block(2, 1, color);
            b4 = new Block(2, 0, color);
        }
        public override void Rotate(byte repeat)
        {
            for (int i = 0; i < repeat; i++)
            {
                switch (this.Position)
                {
                    case Angle.Degree0:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 1,-1);
                            b3.ChangeCoordinates(-1, 1);
                            b4.ChangeCoordinates( 0, 2);
                        }break;
                    case Angle.Degree90:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 1, 1);
                            b3.ChangeCoordinates(-1,-1);
                            b4.ChangeCoordinates(-2, 0);
                        } break;
                    case Angle.Degree180:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates(-1, 1);
                            b3.ChangeCoordinates( 1,-1);
                            b4.ChangeCoordinates( 0,-2);
                        } break;
                    case Angle.Degree270:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates(-1,-1);
                            b3.ChangeCoordinates( 1, 1);
                            b4.ChangeCoordinates( 2, 0);
                        } break;
                }
            }
        }
    }

    public class Shape_L_reverse : Shape
               
    //  [1]         [2][1]                 [4]
    //  [2][■][4]   [■]     [4][■][2]      [■]
    //              [4]           [1]   [1][2]

    {
        public Shape_L_reverse(ConsoleColor color)
        {
            b1 = new Block(0, 0, color);
            b2 = new Block(0, 1, color);
            b3 = new Block(1, 1, color);
            b4 = new Block(2, 1, color);
        }
        public override void Rotate(byte repeat)
        {
            for (int i = 0; i < repeat; i++)
            {
                switch (this.Position)
                {
                    case Angle.Degree0:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 2, 0);
                            b2.ChangeCoordinates( 1,-1);
                            b4.ChangeCoordinates(-1, 1);
                        } break;
                    case Angle.Degree90:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 0, 2);
                            b2.ChangeCoordinates( 1, 1);
                            b4.ChangeCoordinates(-1,-1);
                        } break;
                    case Angle.Degree180:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates(-2, 0);
                            b2.ChangeCoordinates(-1, 1);
                            b4.ChangeCoordinates( 1,-1);
                        } break;
                    case Angle.Degree270:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 0,-2);
                            b2.ChangeCoordinates(-1,-1);
                            b4.ChangeCoordinates( 1, 1);
                        } break;
                }
            }
        }
    }
    
    public class Shape_T : Shape

    //     [4]      [1]                     [3]
    //  [1][■][3]   [■][4]   [3][■][1]   [4][■]
    //              [3]         [4]         [1]

    {
        public Shape_T(ConsoleColor color)
        {
            b1 = new Block(0, 1, color);
            b2 = new Block(1, 1, color);
            b3 = new Block(2, 1, color);
            b4 = new Block(1, 0, color);
        }
        public override void Rotate(byte repeat)
        {
            for (int i = 0; i < repeat; i++)
            {
                switch (this.Position)
                {
                    case Angle.Degree0:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 1,-1);
                            b3.ChangeCoordinates(-1, 1);
                            b4.ChangeCoordinates( 1, 1);
                        } break;
                    case Angle.Degree90:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates( 1, 1);
                            b3.ChangeCoordinates(-1,-1);
                            b4.ChangeCoordinates(-1, 1);
                        } break;
                    case Angle.Degree180:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates(-1, 1);
                            b3.ChangeCoordinates( 1,-1);
                            b4.ChangeCoordinates(-1,-1);
                        } break;
                    case Angle.Degree270:
                        {
                            ChangePositionAnge();
                            b1.ChangeCoordinates(-1,-1);
                            b3.ChangeCoordinates( 1, 1);
                            b4.ChangeCoordinates( 1,-1);
                        } break;
                }
            }
        }
    }    
}
